<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>12-案例二动态显示时间</title>

</head>
<body>
<div id="times">

</div>
<script type="text/javascript">
    function getD1() {
        //当前时间
        var date = new Date();
        //格式化
        var d1 = date.toLocaleString();
        //获取div
        var div1 = document.getElementById("times");
        div1.innerHTML = d1;
    }

    //使用定时器实现每一秒写一次时间
//    setInterval("getD1();",1000);
    window.setInterval(getD1,1000);

</script>
</body>
</html>